<template>
  <el-dialog
    title="SKU列表"
    :visible.sync="dialogVisible"
    width="800px">
    <el-table
      :data="skuList"
      border
      style="width: 100%">
      <el-table-column align="center" prop="name" label="标题"></el-table-column>
      <el-table-column align="center" prop="price" label="价格" width="120"></el-table-column>
      <el-table-column align="center" fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button style="color: red" type="text" size="mini" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" size="mini" @click="dialogVisible = false" icon="el-icon-circle-check">确 定</el-button>
      <el-button @click="dialogVisible = false" size="mini" icon="el-icon-circle-close">取 消</el-button>
  </span>
  </el-dialog>
</template>

<script>
import {deleteSku, listSkuBySpuId, updateSku} from "@/api/product/sku";

export default {
  name: 'SkuList',
  data() {
    return {
      dialogVisible: false,
      spuId: '',
      skuList: []
    };
  },
  methods: {
    open(spuId) {
      this.spuId = spuId
      this.dialogVisible = true
      this.listSku()
    },
    listSku() {
      listSkuBySpuId(this.spuId).then(res => {
        if (res.success) {
          if (res.success) {
            this.skuList = res.data
          }
        }
      })
    },
    handleDelete(row) {
      deleteSku(row.id).then(res => {
        if (res.success) {
          this.$message.success('删除成功')
          this.listSku()
        }
      })
    }
  }
};

</script>
